#ifndef OFFERMESSAGE_H_
#define OFFERMESSAGE_H_

#include <ariba/ariba.h>
#include "../Sync.h"
#include "../Sync_Regular_File.h"

using namespace std;

using_serialization;

class SyncUpdateMessage : public ariba::Message
{
    VSERIALIZEABLE;

public:
    /// Default constructor, required for automatic de-serialization
    SyncUpdateMessage();
    SyncUpdateMessage(string tag, SyncFileList file_list);

//    OfferMessage();
    virtual ~SyncUpdateMessage();


    SyncFileList get_filelist() const;
    string get_tag() const;


private:
    string tag;
    SyncFileList file_list;
};


sznBeginDefault(SyncUpdateMessage, X)
{
    uint32_t size;

    X && T(tag);

    // BRANCH: Serializer
    if ( X.isSerializer() )
    {
        size = file_list->size();
        X && size;

        for ( list<SyncFilePtr>::iterator it = file_list->begin(); it != file_list->end(); it++ )
        {
            SyncRegularFilePtr file = boost::static_pointer_cast<Sync_Regular_File> (*it);
            string path = file->get_common_path().string();
            uint8_t status = file->get_status();

            X && T(path) && status;
        }

    }

    // BRANCH: Deserializer
    else
    {
        X && size;

        for ( int i=0; i < size; i++ )
        {
            string path;
            uint8_t status;

            X && T(path) && status;

            boost::filesystem::path xpath(path);
            SyncRegularFilePtr file(new Sync_Regular_File(xpath));
            file->set_status(status);

            file_list->push_back(file);
        }
    }
} sznEnd();


#endif /* OFFERMESSAGE_H_ */
